<%--
    Document   : detailAggregation.jsp
    Created on : 2010. 11. 14
    Author     : Jeffrey Ha

--%>

<%@page contentType="text/html" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="net.hekka.canyoutalk.web.vo.LogAggregationVo,
         net.hekka.canyoutalk.web.vo.LogAggregationVoList,
         net.hekka.canyoutalk.data.vo.list.TempLogQueryVoList,
         net.hekka.canyoutalk.data.vo.TempLogQueryVo,
         net.hekka.canyoutalk.web.vo.PageVo,
         java.text.SimpleDateFormat;" %>

<HTML>
    <HEAD>
<!--        <meta http-equiv="refresh" content="20;">-->
        <title> CanYouTalk LogManager</title>
        <link rel="StyleSheet" type="text/css" href="./css/maincss.css" />
    </HEAD>

    <%
        HttpSession httpSession = request.getSession();
        PageVo pageVo = (PageVo) request.getAttribute("pageVo");
        LogAggregationVoList logAggregationVoList = (LogAggregationVoList) request.getAttribute("logAggregationVoList");

        int nowPage = (String) request.getAttribute("nowPage") == null ? 0 : Integer.parseInt((String) request.getAttribute("nowPage"));
        int queryCount = (String) request.getAttribute("queryCount") == null ? 0 : Integer.parseInt((String) request.getAttribute("queryCount"));

        int totalPage = (String) request.getAttribute("totalPage") == null ? 0 : Integer.parseInt((String) request.getAttribute("totalPage"));
        int totalCount = (String) request.getAttribute("totalCount") == null ? 0 : Integer.parseInt((String) request.getAttribute("totalCount"));

    %>

    <script language ="javascript">
        function pageChange(pageNumber, endPage) {
            var form = document.detailAggregationForm;
            form.nowPage.value = '<%=nowPage%>';

            if(pageNumber == 'next'){
                if(parseInt(form.nowPage.value) < parseInt(endPage)){
                    form.nowPage.value = parseInt(form.nowPage.value) + 1;
                }else{
                    alert("다음 페이지가 존재하지 않습니다.");
                    return;
                }
            }else if(pageNumber == 'previous'){
                if(parseInt(form.nowPage.value) > 1){
                    form.nowPage.value = parseInt(form.nowPage.value) - 1;
                }else{
                    alert("이전 페이지가 존재하지 않습니다.");
                    return;
                }
            }else{
                form.nowPage.value=pageNumber;
            }

            form.action = "TempLogQueryServlet?serviceId=getDetailAggregation&nowPage="+form.nowPage.value+"&totalCount="+form.totalCount.value+"&queryCount=10";
            form.submit();

        }

        function closeWindow(){
            window.close();
        }
    </script>

    <body>
        <div id="wrapper">
            <div id="header" align="center">
                <h5> Detail Statement </h5>
            </div>

            <div id="content" align="center">

 <%
        SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
        SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
        SimpleDateFormat dayFormat = new SimpleDateFormat("dd");

        SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
        SimpleDateFormat minuteFormat = new SimpleDateFormat("mm");
        SimpleDateFormat secondFormat = new SimpleDateFormat("ss");

        String bgColor = null;
        String packetColor = null;



        if (logAggregationVoList != null && logAggregationVoList.size() > 0) {      // 0001

%>


            <FORM id ="detailAggregationForm" name="detailAggregationForm" method="post" action ="" accept-charset="UTF-8">
                <input type="hidden" name="nowPage" value ='<%=nowPage%>'>
                <input type="hidden" name="queryCount" value ='<%=queryCount%>'>
                <input type="hidden" name="totalPage" value ='<%=totalPage%>'>
                <input type="hidden" name="totalCount" value ='<%=totalCount%>'>

<%
            for (int j = 0; j < logAggregationVoList.size(); j++) {
                LogAggregationVo logAggregationVo = logAggregationVoList.get(j);

                TempLogQueryVo keyLogQueryVo = logAggregationVo.getKeyLogQueryVo();

%>

                <table  border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
                    <tr>
                        <td nowrap width="40" 	bgcolor = "#336699" align="center"><font color="white">seq</font></td>
                        <td nowrap width="130" bgcolor = "#336699" align="center"><font color="white"> Owner </font></td>
                        <td nowrap width="130" bgcolor = "#336699" align="center"><font color="white"> Friend	</font></td>
                        <td nowrap width="40" 	bgcolor = "#336699" align="center"><font color="white"> Status 	</font></td>
                        <td nowrap width="40"  bgcolor = "#336699"	align="center"><font color="white"> check 	</font></td>
                        <td nowrap width="200" bgcolor = "#336699" align="center"><font color="white"> packet_text 	</font></td>
                        <td nowrap width="30"  bgcolor = "#336699"	align="center"><font color="white"> T</font></td>
                        <td nowrap width="100" bgcolor = "#336699"	align="center"><font color="white"> time			</font></td>
                        <td nowrap width="100" bgcolor = "#336699"	align="center"><font color="white"> link seq		</font></td>
                    </tr>


            <%
                    String myNumber = keyLogQueryVo.getMyNumber();
                    String myName = keyLogQueryVo.getMyName();
                    String yourNumber = keyLogQueryVo.getYourNumber();
                    String yourName = keyLogQueryVo.getYourName();
                    int sequence = keyLogQueryVo.getSequence();
                    String status = keyLogQueryVo.getStatus();
                    String checkNumber = keyLogQueryVo.getCheckNumber();
                    String packetData = keyLogQueryVo.getPacketData();
                    long busyMinute = keyLogQueryVo.getBusyMinute();

                    String year = yearFormat.format(keyLogQueryVo.getWriteTime());
                    String month = monthFormat.format(keyLogQueryVo.getWriteTime());
                    String day = dayFormat.format(keyLogQueryVo.getWriteTime());
                    String hour = hourFormat.format(keyLogQueryVo.getWriteTime());
                    String minute = minuteFormat.format(keyLogQueryVo.getWriteTime());
                    String second = secondFormat.format(keyLogQueryVo.getWriteTime());
                    String writeTimeString = year + "." + month + "." + day + "\t" + hour + ":" + minute + ":" + second;

                    int linkSequence = keyLogQueryVo.getLinkSequence();

                    if ( status.equals("NLN") ) {
                        bgColor = "#55CC11";
                    } else if ( status.equals("FLN") ) {
                        bgColor = "#FF3333";
                    } else if ( status.equals("BSY") ) {
                        bgColor = "#FF9922";
                    } else {
                        bgColor = "#D4D4D4";
                    }


                    if ( packetData.substring(0, 2).equals("Soc") ) {
                        packetColor = "#77AAFF";
                    } else if ( packetData.substring(0, 2).equals("CHG") && packetData.substring(6, 8).equals("NLN") ) {
                        packetColor = "#55CC11";
                    } else if ( packetData.substring(0, 2).equals("CHG") && packetData.substring(6, 8).equals("FLN") ) {
                        packetColor = "#FF3333";
                    } else if ( packetData.substring(0, 2).equals("CHG") && packetData.substring(6, 8).equals("BSY") ) {
                        packetColor = "#FF9922";
                    } else {
                        packetColor = "#FFFFFF";
                    }

            %>

                    <tr>
                        <td nowrap  bgcolor="#FFFFFF" align="center"><%=sequence%></td>
                        <td nowrap  bgcolor="#FFFFFF" align="center"><b><%=myName%></b><br/><%=myNumber%></td>
                        <td nowrap  bgcolor="#FFFFFF" align="center"><b><%=yourName%></b><br/><%=yourNumber%></td>
                        <td nowrap  bgcolor="<%=bgColor%>" align="center"> 		<%=status%>		</td>
                        <td nowrap  bgcolor="#FFFFFF" align="center"><%=checkNumber%></td>
                        <td nowrap  bgcolor=<%=packetColor%>  align="left">&nbsp;<%=packetData%>	</td>
                        <td nowrap  bgcolor="#FFFFFF" align="center"> 				<%=busyMinute%>		</td>
                        <td nowrap width="90" nowrap height="30" bgcolor="#FFFFFF" align="center"><%=writeTimeString%>	</td>
                        <td nowrap bgcolor="#FFFFFF" align="center"> 				<%=linkSequence%>		</td>
                    </tr>
                    <br/>

<%
                    TempLogQueryVoList tempLogQueryVoList2 = logAggregationVo.getLogQueryVoList();

                    if (tempLogQueryVoList2 != null && tempLogQueryVoList2.size() > 0) {      // 0002
%>
                    <tr>
                        <td nowrap width="40" 	bgcolor = "#116622" align="center"><font color="white">seq</font></td>
                        <td nowrap width="130" bgcolor = "#116622" align="center"><font color="white"> Owner </font></td>
                        <td nowrap width="130" bgcolor = "#116622" align="center"><font color="white"> Friend	</font></td>
                        <td nowrap width="40" 	bgcolor = "#116622" align="center"><font color="white"> Status 	</font></td>
                        <td nowrap width="40"  bgcolor = "#116622"	align="center"><font color="white"> check 	</font></td>
                        <td nowrap width="200" bgcolor = "#116622" align="center"><font color="white"> packet_text 	</font></td>
                        <td nowrap width="30"  bgcolor = "#116622"	align="center"><font color="white"> T</font></td>
                        <td nowrap width="100" bgcolor = "#116622"	align="center"><font color="white"> time			</font></td>
                        <td nowrap width="100" bgcolor = "#116622"	align="center"><font color="white"> link seq		</font></td>
                    </tr>

<%
                       for (int ii = 0; ii < tempLogQueryVoList2.size(); ii++) {

                            TempLogQueryVo tempLogQueryVo = tempLogQueryVoList2.get(ii);

                            String myNumber1 = tempLogQueryVo.getMyNumber();
                            String myName1 = tempLogQueryVo.getMyName();
                            String yourNumber1 = tempLogQueryVo.getYourNumber();
                            String yourName1 = tempLogQueryVo.getYourName();
                            int sequence1 = tempLogQueryVo.getSequence();
                            String status1 = tempLogQueryVo.getStatus();
                            String checkNumber1 = tempLogQueryVo.getCheckNumber();
                            String packetData1 = tempLogQueryVo.getPacketData();
                            long busyMinute1 = tempLogQueryVo.getBusyMinute();

                            String year1 = yearFormat.format(tempLogQueryVo.getWriteTime());
                            String month1 = monthFormat.format(tempLogQueryVo.getWriteTime());
                            String day1 = dayFormat.format(tempLogQueryVo.getWriteTime());
                            String hour1 = hourFormat.format(tempLogQueryVo.getWriteTime());
                            String minute1 = minuteFormat.format(tempLogQueryVo.getWriteTime());
                            String second1 = secondFormat.format(tempLogQueryVo.getWriteTime());
                            String writeTimeString1 = year + "." + month + "." + day + "\t" + hour + ":" + minute + ":" + second;

                            int linkSequence1 = tempLogQueryVo.getLinkSequence();

                            if ( status1.equals("NLN") ) {
                                bgColor = "#55CC11";
                            } else if ( status1.equals("FLN") ) {
                                bgColor = "#FF3333";
                            } else if ( status1.equals("BSY") ) {
                                bgColor = "#FF9922";
                            } else {
                                bgColor = "#D4D4D4";
                            }


                    if ( packetData1.substring(0, 2).equals("Soc") ) {
                        packetColor = "#77AAFF";
                    } else if ( packetData1.substring(0, 2).equals("CHG") && packetData1.substring(6, 8).equals("NLN") ) {
                        packetColor = "#55CC11";
                    } else if ( packetData1.substring(0, 2).equals("CHG") && packetData1.substring(6, 8).equals("FLN") ) {
                        packetColor = "#FF3333";
                    } else if ( packetData1.substring(0, 2).equals("CHG") && packetData1.substring(6, 8).equals("BSY") ) {
                        packetColor = "#FF9922";
                    } else {
                        packetColor = "#FFFFFF";
                    }

%>

                    <tr>
                        <td nowrap  bgcolor="#FFFFFF" align="center"><%=sequence1%></td>
                        <td nowrap  bgcolor="#FFFFFF" align="center"><b><%=myName1%></b><br/><%=myNumber1%></td>
                        <td nowrap  bgcolor="#FFFFFF" align="center"><b><%=yourName1%></b><br/><%=yourNumber1%></td>
                        <td nowrap  bgcolor="<%=bgColor%>" align="center"> 		<%=status1%>		</td>
                        <td nowrap  bgcolor="#FFFFFF" align="center"><%=checkNumber1%></td>
                        <td nowrap  bgcolor=<%=packetColor%>  align="left">&nbsp;<%=packetData1%>	</td>
                        <td nowrap  bgcolor="#FFFFFF" align="center"> 				<%=busyMinute1%>		</td>
                        <td nowrap width="90" nowrap height="30" bgcolor="#FFFFFF" align="center"><%=writeTimeString1%>	</td>
                        <td nowrap bgcolor="#FFFFFF" align="center"> 				<%=linkSequence1%>		</td>
                    </tr>

<%
                        }
                    }
%>

<%
                }
%>
                </table>

                <br/>

                <br/>

                <%
                }
                %>

                <table>
                    <tr>
                        <td align="center" width="450">&nbsp;
                        <IMG SRC="image/btn_notice_prev.png" WIDTH="17" HEIGHT="12" BORDER="0" ALT=""  style="cursor:pointer;" onclick="pageChange('previous', '<%=pageVo.getPageEndNumber()%>');">
                        <%
                            for (int i = pageVo.getPageStartNumber(); i <= pageVo.getPageEndNumber(); i++) {
                                if (i == nowPage) {
                        %>
                        <a href ="javascript:pageChange('<%=i%>','<%=pageVo.getPageEndNumber()%>');"><b><%=i%></b></a>&nbsp;
                        <%
                                } else {
                        %>
                        <a href ="javascript:pageChange('<%=i%>','<%=pageVo.getPageEndNumber()%>');"><%=i%></a>&nbsp;
                        <%
                                }
                            }
                        %>
                        <IMG SRC="image/btn_notice_next.png" WIDTH="17" HEIGHT="12" BORDER="0" ALT="" style="cursor:pointer;" onclick="pageChange('next', '<%=pageVo.getPageEndNumber()%>');">

                        </td>
                    </tr>
                </table>

</FORM>

            </div>
        </div>
    </body>

</HTML>
